//
//  LCFileDetailVC.m
//  LongChain
//
//  Created by FengZi on 2018/4/25.
//  Copyright © 2018年 FengZi. All rights reserved.
//

#import "LCFileDetailVC.h"

@interface LCFileDetailVC ()


@property (weak, nonatomic) IBOutlet UIImageView *fileImageView;

@end

@implementation LCFileDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSString *imageURL = [NSString stringWithFormat:@"%@%@",BASEURL,self.imageURL];
    [self.fileImageView sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:nil options:SDWebImageRetryFailed];
}


- (IBAction)saveFile:(id)sender {
    
    UIImageWriteToSavedPhotosAlbum(self.fileImageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
    
}

//必要实现的协议方法, 不然会崩溃
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    
    
    LCLog(@"%@",error);
    if (!error) {
        [self showHint:@"保存成功"];
    }
}

- (IBAction)delFile:(id)sender {
    
    NSInteger fileID = [self.file_id integerValue];
    NSDictionary *dic = @{@"file_id":@(fileID)};
    [[LCNetwork shareInstance]lc_postNetworkWithRUL:@"/api/v0/nas/file/delete" parameter:dic responseSuccess:^(id resultCode, id resultParameter) {
        
        if ([resultCode isEqualToString:@"0"]) {
            LCLog(@"resultParameter = %@",resultParameter);
            [self.navigationController popViewControllerAnimated:YES];
        }
    } responseFail:^(id resultCode, NSError *error) {
        
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
    if ([segue.identifier isEqualToString:@"showIdentifierVC"]) {
        id vc = segue.destinationViewController;
        [vc setValue:self.file_id forKey:@"fileID"];
    }
}


@end
